home *** CD-ROM | disk | FTP | other *** search
/ Best of www.BestZips.com (Collector's Edition) / Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO / gamebord / chsclk20.zip / CHESSCLK.HPP < prev    next >
C/C++ Source or Header  |  1996-10-23  |  4KB  |  179 lines

  1. // Chess clock header file
  2. // M\Cooper, PO Box 237, St. David, AZ 85630-0237
  3. // E-mail: thegrendel@theriver.com
  4. /***************************************************************************/
  5.  
  6. extern "C" two_tone(),
  7.        blatt(),
  8.     beep1(),
  9.     beep2();
  10.  
  11. #define PLAY 1
  12. #define GAME_OVER 1
  13. #define QUIT 2    
  14. #define ESC 27
  15. #define MAXLEN 4
  16. #define BUFSIZE 12
  17. #define BLK_TIME 460
  18. #define NAME_POS 530
  19. #define Y_TIMEPOS 300
  20. #define POS_OFFSET 158
  21. #define POS1_OFFSET 130
  22. #define COLORS 15
  23. #define PATTERNS 11
  24. #define RADIUS 50
  25. #define X_C 315
  26. #define Y_C 225
  27. #define MOVES_X 316
  28. #define MOVES_Y 440
  29.  
  30. typedef enum { FALSE, TRUE } BOOLEAN;
  31.  
  32.    enum FLAG { OFF, ON };
  33.    enum Player { WHITE_, BLACK_ };
  34.  
  35.    const char *player[] = { "White", "Black" };
  36.    char  PauseMessage[] = "***paused***";
  37.  
  38. void graphics_setup( int );
  39.  
  40.  
  41.  
  42. class CountdownTimer
  43.    {
  44.    protected:
  45.       int hours,
  46.       minutes,
  47.       moves,
  48.       warning,
  49.       text_color;
  50.       char line_clear [ BUFSIZE ];
  51.      Player p,
  52.            pp;
  53.       FLAG running_flag,
  54.        visual_ticking_flag,
  55.        time_warning_flag,
  56.     overtime_flag,
  57.     toFLAG;
  58.       time_t seconds,
  59.          total_seconds,
  60.          start_t,
  61.          end_t,
  62.          startn_t,
  63.          interval_t,
  64.          running_t,
  65.       pause_t,
  66.       pause_start_t;
  67.    public:
  68.       CountdownTimer()
  69.       {
  70.        hours = 2; minutes = moves = 0; seconds = 0L;
  71.        total_seconds = hours * 3600 + minutes * 60;
  72.        p = WHITE_;
  73.       }
  74.       CountdownTimer( int hrs, int min, time_t sec, Player pl )
  75.       {
  76.       hours = hrs; minutes = min; seconds = sec; moves = 0;
  77.       total_seconds = hours * 3600 + minutes * 60 + seconds;
  78.       p = pl;
  79.       }
  80.       CountdownTimer( int min, time_t sec, Player pl )
  81.       { 
  82.       sec += min * 60;
  83.       total_seconds = sec; 
  84.       hours = sec / 3600;
  85.       minutes = ( sec % 3600 ) / 60;
  86.       seconds = sec % 60;
  87.       moves = 0;
  88.       p = pl;
  89.       }
  90.       CountdownTimer( int hrs, int min, Player pl )
  91.      {
  92.      hours = hrs; minutes = min; seconds = 0L; moves = 0;
  93.      total_seconds = hours * 3600 + minutes * 60;
  94.      p = pl;
  95.      }
  96.       CountdownTimer( time_t sec, Player pl )
  97.       {
  98.       total_seconds = sec;
  99.       convert( sec );
  100.       p = pl;
  101.       moves = 0;
  102.       }
  103.       void convert( time_t sec )
  104.       { 
  105.       hours = sec / 3600;
  106.       sec %= 3600;
  107.       minutes = sec / 60;
  108.       seconds = sec % 60;
  109.       }
  110.  
  111.       void display_time()
  112.       {
  113.       char dbuff [ BUFSIZE ];
  114.  
  115.          sprintf( dbuff,  "%02d:%02d:%02ld", hours, minutes, seconds );
  116.  
  117.          erase_numbers();  // Wipe off old time.
  118.          
  119.          setcolor( text_color );
  120.          outtextxy( p * BLK_TIME, Y_TIMEPOS, dbuff );
  121.          sprintf( line_clear, dbuff );
  122.       }
  123.  
  124.       BOOLEAN timeout()
  125.      {
  126.      if( !hours )
  127.         if( !minutes )
  128.            if( !seconds )
  129.           {
  130.           two_tone();
  131.           return ( TRUE );
  132.           }
  133.      return ( FALSE );
  134.      }
  135.  
  136.       void exit_()
  137.       { 
  138.      char buff [20];
  139.  
  140.  
  141.       if( p )
  142.      sprintf( buff, "Black out of time." );
  143.       else
  144.      sprintf( buff, "White out of time." );
  145.  
  146.       setcolor( RED );
  147.       settextstyle( TRIPLEX_FONT, HORIZ_DIR, 1 );
  148.       outtextxy( 460, 440, buff );
  149.  
  150.       sprintf( buff, "PRESS A KEY" );
  151.       outtextxy( 460, 460, buff );
  152.  
  153.       getch();
  154.       closegraph();
  155.       exit ( GAME_OVER );
  156.       }
  157.  
  158.       void initialize_clock()
  159.       {
  160.       running_flag = OFF;  //Clock is running.
  161.       overtime_flag = OFF; //Normal countdown.
  162.       running_t = 0;
  163.       start_t = time( NULL );
  164.       }
  165.  
  166.       void clock_on(),
  167.        erase_numbers(),
  168.        display_moves(),
  169.         ShowFlag(),
  170.         pause(),
  171.         Write_Message( int Px, int Py, char* Pmessage, int Color );
  172.  
  173.     friend void play();
  174.     friend void exit__();
  175.  
  176.     
  177.     }; //end class defn.
  178.  
  179.